﻿<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@page import="global.Constants"%>
    <%@page import="util.ServletHelp"%>
     <%@page import="com.aiflow.Action.DepartmentAction"%>
<%@page import="com.aiflow.Action.DictionaryAction;"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
	<%
		String baseUrl = request.getContextPath();
	%>
	<script type="text/javascript">
	    //这里的全局是为了修改之后的刷新
	    var alarmQueryListGrid;
	    var alarmQueryListStore;
	    var searchAlarmWindow;
		$(document).ready(function(){
			 // 全局参数
			var baseParams = {limit:<%=Constants.PAGE_SIZE %>,start : 0,alarmStatus : 1};
			var EXT_QUERY_TIME_OUT = 1200000;

			// 传报数据源  userName,u.telep ,d.name as targetName
		    alarmQueryListStore = new Ext.data.JsonStore({
		        url: '${pageContext.request.contextPath}/alarm_findAlarm.action',
		        root: 'datas',
				timeout : EXT_QUERY_TIME_OUT,
		        totalProperty: 'results',
		        fields: ['id','Alarm_id','snumbe','Region_name','Alarm_pro','Dn','Dn_type','Alarm_title','Alarm_time','alarm_status','alarm_type'],
		        baseParams: baseParams,
		        autoLoad: true,
				listeners : {  
                load : function() {  
              isDetailReady = true;// 查询置换标志为已查过   
            }  
            }  
		    });
		    
		      // 区域  数据源  getDepartmentCombo
	          var regionStore = new Ext.data.ArrayStore({  
	            fields : ['region_id', 'region_name'],  
	            data : <%=DepartmentAction.getDepartmentNameCombo("1")%>,
	            sortInfo: {field: "region_id", direction: "ASC"}
	        });
		    
		    //      告警状态
	        var alarmStore = new Ext.data.ArrayStore({  
                    fields : ['status', 'statusName'],  
		            data : <%=ServletHelp.getArrayFromMap(Constants.ALARM_STATUS_MAP, null)%>,
		            sortInfo: {field: "status", direction: "ASC"}
	        });
	       
	        	        var alarmQueryStore = new Ext.data.ArrayStore({  
                    fields : ['alarmQuery', 'alarmQueryName'],  
		            data : <%=ServletHelp.getArrayFromMap(Constants.ALARM_STATUS_QUERY_MAP, null)%>,
		            sortInfo: {field: "alarmQuery", direction: "ASC"}
	        });
	     
			
			 var alarmStatusCombo = new Ext.form.ComboBox({
				id :'alarmStatusCombo', 
			    hiddenName: 'alarmStatus',
				triggerAction: 'all', 
				typeAhead: true, 
				store: alarmStore, 
				mode : 'local',
				valueField: 'status', 
				displayField: 'statusName', 
				editable: true, 
				lazyRender: true,
				allowBlank:false
			});
			
			var statusQueryCombo = new Ext.form.ComboBox({
				id :'statusQueryCombo', 
				//   hiddenName: 'statusQueryCombo',
				triggerAction: 'all', 
				typeAhead: true, 
				store: alarmQueryStore, 
				mode : 'local',
				valueField: 'alarmQuery', 
				displayField: 'alarmQueryName', 
				editable: true, 
				width:100,
				lazyRender: true,
				allowBlank:true
			});
			  
		       // 告警类型  数据源  getDepartmentCombo  （一级告警）
	           var alarmTypeStore = new Ext.data.ArrayStore({  
                    fields : ['alarTyid', 'alarTyname'],  
		            data : <%=DictionaryAction.getDictionaryCombo("79")%>,
		            sortInfo: {field: "alarTyid", direction: "ASC"}
	           });
	        
	        	var alarTyCombo = new Ext.form.ComboBox({
				id :'alarTy', 
			    //hiddenName: 'alarTy',
				triggerAction: 'all', 
				typeAhead: true, 
				store: alarmTypeStore, 
				mode : 'local',
				valueField: 'alarTyid', 
				displayField: 'alarTyname', 
				editable: true, 
				lazyRender: true,
				allowBlank:false
			});
		 
		   // 工具栏
		   var alarmQueryListToolbar = new Ext.Toolbar({
		    	renderTo: 'alarmQueryListToolBarDiv',
		    	items: [
					new Ext.Button({
					    id: 'alarm-save-button',
					    text: '保存',
						iconCls: 'lightning_go'
					}),
						new Ext.Button({
					    id: 'alarm-delete-button',
					    text: '删除',
						iconCls: 'lightning_delete'
					}),'-',
						new Ext.Button({
					    id: 'alarm-export-button',
					    text: '告警导出',
						iconCls: 'page_white_excel'
					}),'-',
					new Ext.Button({
					    id: 'alarm-search-button',
					    text: '拨打记录',
						iconCls: 'note_edit'
					}),
					'-','查询：','区域',
					{  
			                xtype:'combo',
			                id:'regionn',
			                hiddenName: 'region',
			                fieldLabel: '省市',
			                store: regionStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'region_id',
			                displayField: 'region_name',
			                allowBlank:true,
			                editable: false,
			                width: 100,
			                anchor:'98%'
			           },
			             '&nbsp;&nbsp;告警状态',
			              statusQueryCombo,
			                '-','告警时间：',' 起',
					   {  
			                xtype:'datefield',
			                id:'alarmStartTime',
			                hiddenName: 'startTime',
			                fieldLabel: '开始',
                            format:'Y-m-d',
			                mode : 'local',
			                triggerAction: "all",
			                allowBlank:true,
			                editable: false,
			                width: 100,
							vtype : 'daterange',
			                anchor:'98%',
							endDateField : 'alarmEndTime'
			           },' 止 ',
			           {  
			                xtype:'datefield',
			                id:'alarmEndTime',
			                hiddenName: 'endTime',
			                fieldLabel: '开始',
                            format:'Y-m-d',
			                mode : 'local',
			                triggerAction: "all",
			                allowBlank:true,
			                editable: false,
							vtype : 'daterange',
			                width: 100,
			                anchor:'98%',
							startDateField : 'alarmStartTime'
			           },'-',
		                {// 告警标题
			                xtype:'textfield',
			                id:'alarm_title',
			                name: 'alarm_title',
			                emptyText: '请输入告警标题名称',
			                anchor:'98%',
			                width: 120,
			                maxLength: 20
			           },
		             new Ext.Button({
					    id: 'alarm-query-button',
					    text: '查询',
						iconCls: 'magnifier'
					})
				]
			});

			// 数据表格    dept_name spec
			var sm = new Ext.grid.CheckboxSelectionModel();
			alarmQueryListGrid = new Ext.grid.EditorGridPanel({
				id: 'alarmQueryListGrid',
				renderTo: 'alarmQueryListGridDiv',
				border: false,
				stateful: true,
			    autoScroll: 'auto',
		        store: alarmQueryListStore,
		        loadMask: true,
		        cm: new Ext.grid.ColumnModel({
		            defaults: {
		                width: 100,
		                sortable: true
		            },
			        columns: [   //id,Alarm_id,Region_name,Alarm_pro,Dn,Dn_type,Alarm_time,Org_severity
						sm,
					    new Ext.grid.RowNumberer({header:'№',width:50}),
						{id:'id',header: '用户ID', width: 100, hidden: true, sortable: true, dataIndex: 'id'},
						{id:'snumbe',header: '告警流水号', width: 130, hidden: false, sortable: true , dataIndex: 'snumbe'},
						{id:'Alarm_time',header: '告警时间', width: 100, hidden: false, sortable: true , dataIndex: 'Alarm_time'},
			            {id:'Region_name',header: '地市', width: 100,hidden: false, sortable: true, dataIndex: 'Region_name'},
			            {id:'Alarm_title',header: '告警标题', width: 200,hidden: false, sortable: true, dataIndex: 'Alarm_title'},
			            {id:'Alarm_pro',header: '告警专业', width: 100,hidden: false, sortable: true, dataIndex: 'Alarm_pro'},
			            {id:'Dn',header: '网元名称', width: 230,hidden: false, sortable: true, dataIndex: 'Dn'},
                        {id:'Dn_type',header: '网元类型', width: 150,hidden: false, sortable: true, dataIndex: 'Dn_type'},
			            {id:'alarm_status',header: '告警状态', width: 120,hidden: false, sortable: true, dataIndex: 'alarm_status',editor: alarmStatusCombo,renderer: function(value, cellmeta,record){return statusComboRenderer(value, cellmeta,record);}},
			          //        {id:'alarm_type',header: '告警类型', width: 150,hidden: false, sortable: true, dataIndex: 'alarm_type'} ,
			           {id:'alarm_type',header: '告警类型', width: 120,hidden: false, sortable: true, dataIndex: 'alarm_type',editor:alarTyCombo,renderer: function(value, cellmeta,record){return typeComboRenderer(value, cellmeta,record);}}
			             ]
		        }),
		        sm: sm,
		        columnLines: true,
		         bbar: new Ext.PagingToolbar({
					pageSize: <%=Constants.PAGE_SIZE %>,
					store: alarmQueryListStore,
					displayInfo: true,
					displayMsg: Anynote.PAGINGTOOLBAR_DISPLAYMSG,
					emptyMsg: Anynote.PAGINGTOOLBAR_EMPTYMSG,
					doLoad: function(start){
                        baseParams.start = start;
						var reg = Ext.getCmp("regionn").getValue();
			            var status = Ext.getCmp("statusQueryCombo").getValue();
			            var startTime = Ext.getCmp("alarmStartTime").getValue();
					    var endTime = Ext.getCmp("alarmEndTime").getValue();
					    var alarmTitle = Ext.getCmp("alarm_title").getValue();
			            baseParams.region = reg;
			            baseParams.alarmStatus = status;
			            baseParams.startTime = startTime;
				        baseParams.endTime = endTime;
				        baseParams.alarmTitle = alarmTitle;
						this.store.load({params: baseParams});
					}
		        })
		    });

			// 设置Grid高度和宽度
		    Anynote.resizeGridTo("alarmQueryListGrid", 0, 56);
			 
		    // 类型ComboBox设值  
 
			function statusComboRenderer(value, cellmeta,record){
			       
				var index = alarmStore.find(Ext.getCmp('alarmStatusCombo').valueField,value);
				var record = alarmStore.getAt(index);
				var displayText = "";
				
				if(record==null){
					displayText = value;
				}else{
					displayText = record.data.statusName;
				}
				return displayText;
			}
			
			function typeComboRenderer(value, cellmeta,record){
		// 	 alert(Ext.getCmp('alarmStatusCombo').valueField);
				var index = alarmTypeStore.find(Ext.getCmp('alarTy').valueField,value);
				 
				var record = alarmTypeStore.getAt(index);
				var displayText = "";
				
				if(record==null){
					displayText = value;
				}else{
					displayText = record.data.alarTyname;
				}
				return displayText;
			}
		})  
	
				    // 类型ComboBox设值  
			      //    根据状态值 变颜色
			   
		     alarmQueryListGrid.getStore().on('load',function(s,records){
              var girdcount=0;
                s.each(function(r){
                   
            if(r.get('alarm_status')=='1'){
                alarmQueryListGrid.getView().getRow(girdcount).style.backgroundColor='#FF6600';
            }else if(r.get('alarm_status')=='0'){
                alarmQueryListGrid.getView().getRow(girdcount).style.backgroundColor='#00ff66';
              } 
            girdcount=girdcount+1;
        });
         
      });      
      
      
      $("#alarm-save-button").click(function(){
				var records = alarmQueryListStore.getModifiedRecords();
			    var valt = '';
				if(records.length != 0){
				for(var i = 0; i < records.length; i++) {
    	         record = records[i];
    	          if(record.isModified('alarm_type')){
    	           //   var valu = record.get('Alarm_id');
    	            valt=valt+','+i;
    	          }
    	         } 
    	         if(  valt !='' && valt.length>0){
    	           valt = valt.substring(1,valt.length);
    	         } 
					var params = {};
					params.jsonArr = Anynote.convertRecordsToJson(records);

					// 发送请求
					Anynote.ajaxRequest({
						baseUrl: '<%=baseUrl %>',
						baseParams: params,
						action: '${pageContext.request.contextPath}/alarm_saveAlarm.action?val='+valt,
						callback: function(jsonResult){
							  alarmQueryListGrid.getStore().reload();  
						},
						showWaiting: true,
						failureMsg: '保存失败.'
					});
				}
			});
			
			
			 $("#alarm-query-button").click(function(){
			    // alarmQueryListStore
			   var reg = Ext.getCmp("regionn").getValue();
			   var status = Ext.getCmp("statusQueryCombo").getValue();
			   var startTime = Ext.getCmp("alarmStartTime").getValue();
			   var endTime = Ext.getCmp("alarmEndTime").getValue();
			   var alarmTitle = Ext.getCmp("alarm_title").getValue();
			     var basePar  = {limit:<%=Constants.PAGE_SIZE %>,start : 0};
			       basePar.region = reg;
			       basePar.alarmStatus = status;
			       basePar.startTime = startTime;
			       basePar.endTime = endTime;
			       basePar.alarmTitle = alarmTitle;
			    alarmQueryListStore.reload({params:basePar});
			 })
		
				$("#alarm-delete-button").click(function(){
				// 提交
				var recodes = alarmQueryListGrid.getSelectionModel().getSelections();
				if(recodes.length < 1){
					 Ext.Msg.alert("提示", "请至少选择一条数据.");
				}else{
				  var k = '';
				  var val = '';
				  for(var i = 0;i<recodes.length;i++){
				     k=recodes[i];
				        val += '\''+k.get("Alarm_id")+'\',';
				  }
				
				  Anynote.ajaxRequest({
								baseUrl: '<%=baseUrl %>',
							       baseParams: {alarmIds:val },
								action: '${pageContext.request.contextPath}/alarm_deleteAlarm.action',
								callback: function(jsonResult){
							
									alarmQueryListStore.reload();
								},
								showWaiting: true,
								failureMsg: '保存失败.'
							});
						   }
					     });
					     
			     // 查看拨打记录
				$("#alarm-search-button").click(function(){
				    var records = alarmQueryListGrid.getSelectionModel().getSelections();
				    if(records.length < 1){
					 Ext.Msg.alert("提示", "请至少选择一条数据.");
				    }else{
				     var alarmIds = "";
				     alarmIds = records[0].get("snumbe");
				     //只能一条一条的查看，不能多个一起查看
					 if(records.length == 1){
					    searchAlarmWindow = new Ext.Window({
								title: '查看拨打记录',
								width: 800,
								height: 400,
								modal: true,
			
								maximizable: false,
								resizable: false,
								layout:'fit',
								iconCls: 'note_edit',
								plain: true,
								autoLoad:{url:'${pageContext.request.contextPath}/page/bussmodule/alarmQuery/searchAlarmQueryConfig.jsp?alarmIds='+alarmIds,scripts:true,nocache:true}
								});
								searchAlarmWindow.show();
					 }else{
					   Ext.Msg.alert("提示", "只能选择一条数据.");
					 }
				    }
				});

			     $("#alarm-export-button").click(function(){   //   下载 
				  var reg = Ext.getCmp("regionn").getValue();
			      var status = Ext.getCmp("statusQueryCombo").getValue();
			            window.location.href = "${pageContext.request.contextPath}/alarm_down.action?region="+reg+"&alarmStatus="+status;
				  })					     
					     
				 
	  
	</script>
</head>
<body>
<div id="alarmQueryListDiv">
	<div id="alarmQueryListToolBarDiv"></div>
	<div id="alarmQueryListGridDiv" style="width:100%;height:100%;"></div>
</div>
</body>
</html>